from classpath.class_path import ClassPath
import struct


class ClassReader:
    def __init__(self, data):
        self.data = data
        self.idx = 0

    def readU8(self):
        dt = self.data[self.idx]
        self.idx += 1
        return dt

    def readU16(self):
        dt = self.data[self.idx:self.idx+2]
        self.idx += 2
        return dt

    def readU32(self):
        dt = self.data[self.idx:self.idx+4]
        self.idx += 4
        return dt

    def readU64(self):
        dt = self.data[self.idx:self.idx+8]
        self.idx += 8
        return dt

    def readU16s(self):
        length = int.from_bytes(self.readU16(), "big")
        dt = []
        for i in range(length):
            dt.append(self.readU16())
        return dt

    def readBytes(self, n):
        dt = bytearray()
        for i in range(n):
            dt.append(self.readU8())
        return dt


if __name__ == '__main__':
    classpath = ClassPath.parse("", "")
    dat = classpath.readClass("System")
    clsReader = ClassReader(dat)
    u16 = clsReader.readU16()
    print(hex(u16[0]), hex(u16[1]))
